package com.dhcc.DRGsHosp.application.impl;

import java.util.List;

import javax.inject.Named;

import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.QueryChannelService;
import org.springframework.transaction.annotation.Transactional;

import com.dhcc.DRGsHosp.application.DoctorMonitorApplication;

@Named
@Transactional
public class DoctorMonitorApplicationImpl implements DoctorMonitorApplication {
	private QueryChannelService queryChannel;

    private QueryChannelService getQueryChannelService(){
       if(queryChannel==null){
          queryChannel = InstanceFactory.getInstance(QueryChannelService.class,"queryChannel");
       }
     return queryChannel;
    }

	@Override
	public String getUserDepCode(String doctor) {
		String depCode = "";
		String sql = "select mr.out_dep_code from drgs.t_medicalrecord mr where mr.pargroup_name = '"+doctor+"' order by mr.out_date desc " ;
		List<String> depCodeList = getQueryChannelService().createSqlQuery(sql).list();
		if (!depCodeList.isEmpty()) {
			depCode = depCodeList.get(0);
		}
		return depCode;
	}
	
	
}
